package com.woniu.common.exceptionResovler;



import com.woniu.common.CustomException.UserException;
import com.woniu.common.vo.AjaxResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
public class GlobalExceptionResovler {


    @ExceptionHandler(Exception.class)
    public AjaxResult handle(Exception e){
        e.printStackTrace();
        if(e instanceof UserException){
            UserException ex = (UserException) e;
            return AjaxResult.error(ex.getMessage());
        }else {
            return AjaxResult.error();
        }
    }
}
